<?php

class Social_Form_Admincp_Browse_Google extends Social_Form_Admincp_Browse_Edit
{

	function init()
	{

		$this -> setTitle('Google Setting');
		$this -> setDesc('form-desc.Google Setting');

		$this -> isAsync();

		$this -> addChild('text', 'key', array(
			'label' => 'Google Api Key',
			'desc' => 'form-desc.Google Api Key'
		));

		$this -> addChild('text', 'secret', array(
			'label' => 'Google Api Secret',
			'desc' => 'form-desc.Google Api Secret'
		));

		$this -> addChild('yesno', 'is_enabled', array('label' => 'Enabled'));

		$this -> addChild('text', 'sort_order', array('label' => 'Sort Order'));

		$this -> addChild('group', '_footer');

		$this -> _footer -> addChild('submit', '_submit') -> addChild('cancel', '_cancel');
	}

	function populate($item)
	{
		$this -> setData($item -> toArray());

		$key = Nuo::getConfig('google','key');

		$secret = Nuo::getConfig('google','secret');

		$this -> getChild('key') -> setValue($key);

		$this -> getChild('secret') -> setValue($secret);
	}

	function commit($item, $data)
	{
		$item -> fromArray($data);
		$item -> save();

		Nuo::getApi('core/config') -> write('google', array(
			'key' => $data['key'],
			'secret' => $data['secret'],
		));

		Nuo_Cache::instance()-> remove('core/config');
	}

}
